package com.chushouya.product.dao.repository;


import com.general.framework.core.lang.Longs;
import com.general.framework.data.mybatis.BaseRepository;
import com.chushouya.product.dao.entity.EvaluateTipsEntity;
import com.chushouya.product.dao.mapper.EvaluateTipsEntityMapper;
import com.chushouya.product.dto.api.evaluatetips.EvaluateTipsQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import java.util.List;


@Repository
@Slf4j
public class EvaluateTipsRepository extends BaseRepository<EvaluateTipsEntityMapper, EvaluateTipsEntity, Long> {


    public List<EvaluateTipsEntity> selectList(EvaluateTipsQuery query) {
        return selectByExample(buildExample(query));
    }


    public EvaluateTipsEntity selectOne(EvaluateTipsQuery query) {
        return selectFirstOneByExample(buildExample(query));
    }

    private Example buildExample(EvaluateTipsQuery query) {
        Example example = this.buildExample();
        if (Longs.notNullAndZero(query.getCategoryId())) {
            example.and().andEqualTo("categoryId", query.getCategoryId());
        }
        if (Longs.notNullAndZero(query.getBrandId())) {
            example.and().andEqualTo("brandId", query.getBrandId());
        }
        return example;

    }
}